import pymysql

file_objects = open(r"D:\birthday.csv", "r")

conn = pymysql.connect(host='localhost', user='root', password='root', database='take_out')
cursor = conn.cursor()
data = file_objects.readlines()
print('data',data)
n = data[0].rstrip('\n').split(',')
cursor.execute("create table birthday ("
               "{} int null,"
               "{} varchar(20) null,"
               "{} int null "
               ")".format(n[0], n[1], n[2]))
for i in range(1, len(data)):
    n = data[i].rstrip('\n')
    data_ = n.split(',')
    print(data_[0], data_[1], data_[2])
    cursor.execute(
        "insert into birthday(id, name, birthday) values ({}, '{}', {})".format(data_[0], data_[1], data_[2]))
    conn.commit()
cursor.close()
conn.close()
print(data)
file_objects.close()
